﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GDFlacTool.Forms
{
    public partial class FormSelectMd5File : Form
    {
        private string[] _md5Files;

        private string _selectedMd5File = string.Empty;

        public FormSelectMd5File(string[] md5Files)
        {
            InitializeComponent();

            _md5Files = md5Files;

            LoadListBox();
        }

        public string SelectedMd5File
        {
            get { return _selectedMd5File; }
        }

        private void LoadListBox()
        {
            foreach (string s in _md5Files)
            {
                ListBoxItem item = new ListBoxItem(Path.GetFileName(s), s);

                lsbSelectFile.Items.Add(item);
            }
        }

        private void lsbSelectFile_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(lsbSelectFile.SelectedItems.Count == 1)
            {
                btnSelect.Enabled = true;
            }
            else
            {
                btnSelect.Enabled = false;
            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            _selectedMd5File = ((ListBoxItem) lsbSelectFile.SelectedItems[0]).Filepath;
        }
    }

    internal class ListBoxItem
    {
        private string _filename = string.Empty;
        private string _filepath = string.Empty;

        public ListBoxItem(string filename, string filepath)
        {
            _filename = filename;
            _filepath = filepath;
        }

        public string Filename
        {
            get { return _filename; }
        }

        public string Filepath
        {
            get { return _filepath; }
        }

        public override string ToString()
        {
            return Filename;
        }
    }
}
